home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / ZIPPED / LISTINGS / V_12_05.ZIP / ALLISON.ZIP / VIDEO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  3.0 KB  |  132 lines

  1. LISTING 11 -
  2. // video.cpp
  3.  
  4. #include <string.h>
  5. #include <dos.h>
  6. #include "video.h"
  7.  
  8. volatile char far * Video::base = Video::init();
  9.  
  10. #if defined(_MSC_VER)    // Microsoft
  11. volatile char far * Video::init()
  12. {
  13.     unsigned seg = (*(unsigned far *) 0x00400063);
  14.     char far *p;
  15.  
  16.     if (seg == 0x3b4)
  17.         _FP_SEG(p) = MONO;
  18.     else
  19.         _FP_SEG(p) = COLOR;
  20.     _FP_OFF(p) = 0;
  21.     return p;
  22. }
  23. #else                    // Borland
  24. volatile char far * Video::init()
  25. {
  26.     unsigned seg = (*(unsigned far *) 0x00400063);
  27.     unsigned vseg;
  28.     
  29.     vseg = (seg == 0x3b4) ? MONO : COLOR;
  30.     return (char far *) MK_FP(vseg,0);
  31. }
  32. #endif
  33.  
  34. void Video::putc(unsigned char c, int row, int col, int attr)
  35. {
  36.     // Display a character
  37.     volatile char far *p = base + row*NCOLS*2 + 2*col;
  38.     *p++ = c;
  39.     *p = attr;
  40. }
  41.  
  42. void Video::puts(char *s, int row, register col, int attr)
  43. {
  44.     // Display a string
  45.     while (col < NCOLS && *s)
  46.         putc(*s++,row,col++,attr);
  47. }
  48.  
  49. void Video::cls(int attr)
  50. {
  51.     // Clear the screen
  52.     union REGS r;
  53.  
  54.     r.h.ah = 6;       // Scroll up (could use 7 = down)
  55.     r.h.al = 0;       // Scroll 0 lines (this clears the screen)
  56.     r.h.bh = (unsigned char) attr;
  57.     r.x.cx = 0;       // Top left = (0,0)
  58.     r.h.dh = NROWS-1; // Bottom right = (24,79)
  59.     r.h.dl = NCOLS-1;
  60.     int86(0x10,&r,&r);
  61. }
  62.  
  63. void Video::message(char *s, int attr)
  64. {
  65.     // Display a string on the status line
  66.     if (s)
  67.     {
  68.         puts(s,NROWS-2,0,attr);
  69.         for (int i = strlen(s); i < NCOLS; ++i)
  70.             putc(' ',NROWS-2,i,attr);
  71.     }
  72. }
  73.  
  74. void Video::save_region(int ulrow, int ulcol, int lrrow, int
  75. lrcol, char *buf)
  76. {
  77.     // Save a rectangular region of the screen
  78.     if (buf)
  79.     {
  80.         volatile char far *p;
  81.         int nbytes = 2*(lrcol-ulcol+1), n;
  82.     
  83.         for (int row = ulrow; row <= lrrow; ++row)
  84.         {
  85.             p = base + (row*NCOLS*2 + 2*ulcol);
  86.             for (n = 0; n < nbytes; ++n)
  87.                 *buf++ = *p++;
  88.         }
  89.     }
  90. }
  91.  
  92. void Video::restore_region(int ulrow, int ulcol, int lrrow, int
  93. lrcol, char *buf)
  94. {
  95.     // Restore a rectangular region to the screen
  96.     if (buf)
  97.     {
  98.         volatile char far *p;
  99.         int nbytes = 2*(lrcol-ulcol+1), n;
  100.     
  101.         for (int row = ulrow; row <= lrrow; ++row)
  102.         {
  103.             p = base + (row*NCOLS*2 + 2*ulcol);
  104.             for (n = 0; n < nbytes; ++n)
  105.                 *p++ = *buf++;
  106.         }
  107.     }
  108. }
  109.  
  110. void Video::clear_region(int ulrow, int ulcol, int lrrow, int
  111. lrcol)
  112. {
  113.     int far *p;
  114.     int n;
  115.     int nchars = (lrcol-ulcol+1);
  116.     const unsigned SPACE = 0x0720;  // Normal space
  117.     
  118.     for (int row = ulrow; row <= lrrow; ++row)
  119.     {
  120.         p = (int far *) (base + (row*NCOLS*2 + 2*ulcol));
  121.         for (n = 0; n < nchars; ++n)
  122.             *p++ = SPACE;
  123.     }
  124. }
  125.  
  126. unsigned Video::type()
  127. {
  128.     // Read video segment (color vs. monochrome)
  129.     return FP_SEG(base);
  130. }
  131.  
  132.